//
//  HCExchangeMineView.m
//  HappyChildren
//
//  Created by WillyZhao on 2017/5/12.
//  Copyright © 2017年 WillyZhao. All rights reserved.
//

#import "HCExchangeMineView.h"

#import "HCExchangeTableViewCell.h"

#import "HCMineExchangeModel.h"


@interface HCExchangeMineView () <UITableViewDelegate,UITableViewDataSource> {
    UITableView *tableView_;
    HCMineExchangeModel *model_;
}

@end

@implementation HCExchangeMineView


-(instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self initializeSubViews:frame];
    }
    return self;
}

-(void)initializeSubViews:(CGRect)frame {
    tableView_ = [[UITableView alloc] initWithFrame:frame];
    tableView_.backgroundColor = [UIColor whiteColor];
    tableView_.showsVerticalScrollIndicator = NO;
    tableView_.delegate = self;
    tableView_.dataSource = self;
    tableView_.rowHeight = YBKAdaptiveH(70);
    tableView_.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self addSubview:tableView_];
    
    //注册cell
    [tableView_ registerNib:[UINib nibWithNibName:@"HCExchangeTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"exchange"];
}

#pragma mark 代理
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (model_) {
        return model_.order.count;
    }else{
        return 0;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HCExchangeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"exchange" forIndexPath:indexPath];
    if (model_) {
        cell.model = (HCMineExchangeData *)model_.order[indexPath.row];
    }
    return cell;
}

-(void)setModel:(id)model {
    model_ = (HCMineExchangeModel *)model;
    [tableView_ reloadData];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
